<?php
class AdminOpenationModel extends MY_Model{
    public $table = 't_admin_operation_log';
    public function __construct(){
        parent::__construct();
    }

    public $type = array(1=>'审核帖子', 2=>"删除帖子", 3=>"帖子审核不通过", 4=>"删除评论", 5=>"修改评论", 6=>"删除帖子图片",
        7=>"删除图片库图片", 8=>"为帖子上传封面图", 9=>"删除管理员", 10=>"开启火眼金精", 11=>"添加管理员", 12=>"编辑用户信息",
        13=>"添加白名单", 14=>"移除白名单", 15=>"开启前端审核", 16=>"添加话题", 17=>"修改话题", 18=>"设置话题标签状态", 19=>"添加标签",
        20=>"修改标签", 21=>"设置标签状态", 22=>"后台登陆成功", 23=>"后台退出成功", 24=>"评论恢复",25=>"被删帖子恢复",
        26 => "修改帖子标题",
        27 => "修改话题聚合页排序",
        35 => "举报审核",
        36 => "审核用户",
    );

    public function insertLog($id='',$type=1,$desc=''){
        //添加修改人信息
        $userData = getLoginUser();
        $this->AdminOpenationModel->insert_one(array('uid'=>$userData['uid'],'nickname'=>$userData['nickname'],'add_time'=>time(),'type'=>$type,'post_id'=>$id,'desc'=>$desc));
        return true;
    }

    /**
     * 取管理员操作记录
     * name: getLogList
     * @param string $uid
     * @param $page
     * @param $pagesize
     * @return array
     * @throws Exception
     * @Author:taiyang
     */
    public function getLogList($uid='',$type='',$s_type='',$post_id='',$page,$pagesize){
        $sql="select u.nickname as u_nickname,u.mobile,a.* from ".$this->table." a left join t_user u on a.uid=u.uid where 1 ";
        $sql.=$this->getSqlWhere($uid,$type,$s_type,$post_id);
        $sql.=" order by a.add_time desc ";
        $index = $page - 1 < 0 ? 0 : ($page - 1) * $pagesize;
        $sql.=" limit ".$index.",".$pagesize."";
        return $this->query_sql_list($sql);

    }

    /**
     * 取管理员操作记录条数
     * name: getLogNum
     * @param string $uid
     * @return int
     * @throws Exception
     * @Author:taiyang
     */
    public function getLogNum($uid='',$type='',$s_type='',$post_id=''){
        $sql="select count(*) from ".$this->table." a left join t_user u on a.uid=u.uid where 1 ";
        $sql.=$this->getSqlWhere($uid,$type,$s_type,$post_id);
        return $this->query_sql_count($sql);
    }

    public function getSqlWhere($uid='',$type='',$s_type='',$post_id=''){
        $sql='';
        if(!empty($uid)){
            $sql.=" and a.uid=".$uid." ";
        }
        if(!empty($type)){
            $sql.=" and a.type=".$type." ";
        }
        if(!empty($post_id)){
            $sql.=" and a.post_id=".$post_id." ";
        }
        if($s_type == 1){
            $sql.=" and a.type in (1,2,3,6,8)";
        }
        return $sql;
    }
}